package com.biz.primus.ms.coupon.dao.po;

import com.biz.primus.model.coupon.enums.CouponGenerateStrategy;
import com.biz.primus.model.coupon.enums.CouponLimitType;
import com.biz.primus.model.coupon.enums.CouponScopeType;
import com.biz.primus.model.coupon.interfaces.IEntitySoftRemoval;
import com.biz.primus.ms.base.jpa.converter.SetLongConverter;
import com.biz.primus.ms.base.jpa.po.BaseEntity;
import java.time.LocalDateTime;
import java.util.Set;
import javax.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 优惠券类型
 *
 * @author david-liu
 */
@Entity
@Table(name = "cpn_coupon_type")
@Getter
@Setter
@NoArgsConstructor
public class CouponType extends BaseEntity implements IEntitySoftRemoval {

    private static final long serialVersionUID = -2000186413844196208L;

    //限制可以使用优惠券的分类id,如果为null或空set,则表示不限制分类
    @Convert(converter = SetLongConverter.class)
    @Column(columnDefinition = "TEXT")
    private Set<Long> categories;

    //限制可以使用优惠券的品牌id,如果为null或空set,则表示不限制品牌
    @Convert(converter = SetLongConverter.class)
    @Column(columnDefinition = "TEXT")
    private Set<Long> brands;

    //限制可以使用的商品id
    @Convert(converter = SetLongConverter.class)
    @Column(columnDefinition = "TEXT")
    private Set<Long> includeProducts;

    //限制不可以使用优惠券的商品id,与includeProducts二选一填写,如果都为空,则不限制商品
    @Convert(converter = SetLongConverter.class)
    @Column(columnDefinition = "TEXT")
    private Set<Long> excludeProducts;

    //限制可以使用优惠券的商家
    @Convert(converter = SetLongConverter.class)
    private Set<Long> vendors;

    //优惠券限制使用类型
    @Enumerated(EnumType.STRING)
    private CouponLimitType couponLimitType;

    //优惠券使用范围类型(平台券/商家券)
    @Enumerated(EnumType.STRING)
    private CouponScopeType couponScopeType;

    // 优惠券生成策略
    @Enumerated(EnumType.STRING)
    private CouponGenerateStrategy couponGenerateStrategy = CouponGenerateStrategy.PRE_BUILD;

    //券类型名称
    @Column(length = 50, nullable = false)
    private String couponTypeName;

    //优惠券介绍
    @Column(columnDefinition = "TEXT")
    private String couponTypeDesc;

    //优惠券面值
    @Column(nullable = false)
    private Integer faceValue;

    //优惠券门槛
    @Column(nullable = false)
    private Integer couponLimitAmount;

    //优惠券可用开始时间
    @Column(nullable = false)
    private LocalDateTime usableStartTime;

    //优惠券可用终止时间
    @Column(nullable = false)
    private LocalDateTime usableEndTime;

    //优惠券可领开始时间
    @Column(nullable = false)
    private LocalDateTime receivableStartTime;

    //优惠券可领终止时间
    @Column(nullable = false)
    private LocalDateTime receivableEndTime;

    //优惠券领取开始之后, 几天后优惠券不可用
    @Column(nullable = false)
    private Integer usableCountDownDays;

    //券类型发行总数 不可修改
    @Column(nullable = false, updatable = false)
    private Integer totalQuantity;

    // 优惠券是否启用
    @Column
    private Boolean enable = true;

    // 优惠券图片, 如果需要使用图片, 赋值
    @Column
    private String icon;

    // 优惠券备注信息
    @Column
    private String remark;

    // 已领取优惠券数量
    @Column
    private Integer receivedQuantity = 0;

    // 优惠券类型创建人
    @Column(length = 50)
    private String creator;

    // 优惠券类型最后更新人
    @Column(length = 50)
    private String lastUpdateUser;

    // 删除日期
    private LocalDateTime deletedAt;

    // 删除标识符
    private Boolean deleteStatus = Boolean.FALSE;

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }
}
